﻿namespace A2;

public class Clock
{
    public event EventHandler Tick;
    
    public event EventHandler Alarm;

    // 闹钟运行的方法
    public void Start(int alarmTime)
    {
        int tickCount = 0;

        while (true)
        {
            Thread.Sleep(1000);
            OnTick(new EventArgs());
            tickCount++;

            if (tickCount == alarmTime)
            {
                OnAlarm(new EventArgs());
                break;
            }
        }
    }
    
    protected virtual void OnTick(EventArgs e)
    {
        Tick?.Invoke(this, e);
    }
    
    protected virtual void OnAlarm(EventArgs e)
    {
        Alarm?.Invoke(this, e);
    }
}